<?php
namespace app\backend\org;

use \think\Db;

class HeadTitle
{
    static public function title($data,$id,$language,$type)
    {
        //系统名称
        $title_system = Db::query("select system_name_cn,system_name_en,img_url from ls_system where `system_id`=1");
        //返回前台的head_title
        $p_id = Crumbs::crumbs($data,$id,$language,$type);
       $temp =  array_reverse($p_id);
//print_r($p_id);exit;
        if($type == "menu"){
            $title = "";
            if($language=="cn"){
                foreach ($temp as $k=>$v){
                        $title .= $v["menu_name"].'-';//.=字符串拼接
                }
                $title .= $title_system[0]["system_name_cn"];
                //array_reverse()
               // $title = $p_id[0]["menu_name_cn"].'-'.$title_system[0]["system_name_cn"];
            }elseif ($language=="en"){
                foreach ($temp as $k=>$v){
                    $title .= $v["menu_name"].'-';//.=字符串拼接
                }
                $title .= $title_system[0]["system_name_en"];
            }
        }elseif ($type == "list"){
            $title = [];
            $length = count($p_id)-1;
            if($language=="cn"){
                for($i=$length; $i>=0; $i--){
                    if($i==$length){
                        $title[] =$p_id[$length]["list_title"] ;
                    }elseif ($i == $length-1){
                        $title[] = $p_id[$length - 1]["tab_name"] ;
                    }else{
                        $title[] = $p_id[$i]["menu_name"] ;
                    }
                }
                $title = implode('-',$title).'-'.$title_system[0]["system_name_cn"];
            }elseif ($language=="en"){
                for($i=$length; $i>=0; $i--){
                    if($i==$length){
                        $title[] =$p_id[$length]["list_title"] ;
                    }elseif ($i == $length-1){
                        $title[] = $p_id[$length - 1]["tab_name"] ;
                    }else{
                        $title[] = $p_id[$i]["menu_name"] ;
                    }
                }
                $title = implode('-',$title).'-'.$title_system[0]["system_name_en"];
            }
        }
       // echo $title;exit;
        return $title;
    }
}